package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.BookingsDatetimeAddDTO;
import org.jsola.hr.dto.BookingsDatetimeUpdateDTO;
import org.jsola.hr.entity.BookingsDatetimeDO;
import org.jsola.hr.query.BookingsDatetimeQuery;
import org.jsola.hr.service.IBookingsDatetimeService;
import org.jsola.hr.vo.BookingsDatetimeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 预约业务时段表
 *
 * @author zhr
 */
@Component
public class BookingsDatetimeTestHelper extends BaseTestHelper {
    
    @Autowired
    private IBookingsDatetimeService bookingsDatetimeService;

    /**
     * 生成add测试数据
     * @return BookingsDatetimeAddDTO
     */
    public BookingsDatetimeAddDTO getBookingsDatetimeAddDTO(){
        BookingsDatetimeAddDTO bookingsDatetimeAddDTO = new BookingsDatetimeAddDTO();
        bookingsDatetimeAddDTO.setBookingsDatetimeRemainingCount(SafeKit.getInteger(getRandomValue("int",10)));
        bookingsDatetimeAddDTO.setBookingsDay((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        bookingsDatetimeAddDTO.setBookingsDatetime(getRandomValue("varchar",50));
        bookingsDatetimeAddDTO.setBookingsDatetimeCount(SafeKit.getInteger(getRandomValue("int",0)));
        bookingsDatetimeAddDTO.setBusinessId(SafeKit.getLong(getRandomValue("bigint",11)));
        return bookingsDatetimeAddDTO;
    }


    /**
     * 生成update测试数据
     * @return BookingsDatetimeUpdateDTO
     */
    public BookingsDatetimeUpdateDTO getBookingsDatetimeUpdateDTO(BookingsDatetimeVO bookingsDatetimeVO){
        return bookingsDatetimeService.selectDOById(bookingsDatetimeVO.getId(), SITE_ID).to(BookingsDatetimeUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return BookingsDatetimeQuery
     */
    public BookingsDatetimeQuery getBookingsDatetimeQuery() {
        BookingsDatetimeQuery bookingsDatetimeQuery = new BookingsDatetimeQuery();
        List<BookingsDatetimeDO> bookingsDatetimeDOList = bookingsDatetimeService.list(new BookingsDatetimeDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(bookingsDatetimeDOList)) {
            BookingsDatetimeDO bookingsDatetimeDO = bookingsDatetimeDOList.get(0);
            bookingsDatetimeQuery = bookingsDatetimeDO.to(BookingsDatetimeQuery.class);
        }
        return bookingsDatetimeQuery;
    }

    /**
     * 保存示例
     * @return BookingsDatetimeVO
     */
    public BookingsDatetimeVO saveBookingsDatetimeExample(){
        BookingsDatetimeAddDTO addDTO = this.getBookingsDatetimeAddDTO();
        BookingsDatetimeVO bookingsDatetimeVO = bookingsDatetimeService.save(addDTO,buildTokenUser());
        return bookingsDatetimeVO;
    }


}

